<?php
include_once 'ZCollection.php';

class ZAuthorCollection extends ZCollection {

    /**
     * @param $item ZAuthorItem
     */
    public function addItem($item){
        $this->items[] = $item;
    }
    /**
     * @param $index
     * @return ZAuthorItem
     */
    public function getIndex($index){
        return $this->items[$index];
    }

    /**
     * @param $arrName array Name of authors
     * @param $arrSource array Source of authors
     * @param $arrNumbers array Number of author's posts
     * @param $top Select top author
     * @param $length Length of thumbnail Author's name
     */
    public function getTopAuthors(&$arrName,&$arrSource, &$arrNumbers, $top, $length){
        for ($i = 0; $i < min($top, $this->getAuthorNumber()); $i++){
            $item = $this->getIndex($i);
            $name = $item->getAuthorName();

            if (mb_strlen($name, 'UTF-8') > $length){
                $arrName[] = mb_substr($name, 0, $length, 'UTF-8') . '...';
            }
            else if (mb_strlen($name) != 0){
                $arrName[] = $name;
            }
            else{
                $name = 'No name';
                $arrName[] = $name;
            }

            $arrSource[] = $item->getSource();

            $arrNumbers[] = array(
              'y'           => $item->getNumberOfPosts(),
              'fullName'    => $name,
              'source'      => $item->getSource()
            );
        }
    }
}